package com.muh.service;

import com.muh.entity.User1;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component
public class CircuitBreakerFallbackFactory implements FallbackFactory<FeignClientService> {
    @Override
    public FeignClientService create(Throwable cause) {
        FeignClientService feignClientService = new FeignClientService() {
            @Override
            public String hello1() {
                return "服务提供者挂了 我是服务消费者的  属于服务降级 ";
            }

            @Override
            public User1 getUserById(Integer id) {
                User1 user1 = new User1();
                user1.setId(id);
                return user1;
            }

            @Override
            public List<User1> getUserByName(String name) {
                ArrayList<User1> user1s = new ArrayList<>();
                User1 user1 = new User1();
                user1.setName(name+"服务提供者挂了 我是服务消费者的  属于服务降级 ");
                user1s.add(user1);
                return user1s;
            }

            @Override
            public int insert(User1 user1) {
                return 0;
            }

            @Override
            public int insertBatch(List<User1> user1List) {
                return 0;
            }

            @Override
            public boolean deleteById(Integer id) {
                return false;
            }

            @Override
            public User1 update(User1 user1) {
                return new User1();
            }

            @Override
            public int insertOrUpdateBatch(List<User1> user1List) {
                return 0;
            }

            @Override
            public List<User1> getUserByNameWithCircuitBreaker(String name) {
                ArrayList<User1> user1s = new ArrayList<>();
                User1 user1 = new User1();
                user1.setName(name+"服务提供者挂了 我是服务消费者的  属于服务降级 ");
                user1s.add(user1);
                return user1s;
            }
        };
        return feignClientService;
    }
}
